﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UniversalUpdater
{
    public partial class UpdaterForm : Form
    {
        UpdaterFunctions uf;
        public UpdaterForm(Version InstalledVersion, string AppUpdateUrl, bool Silent, bool IsXML)
        {
            InitializeComponent();

            uf = new UpdaterFunctions(this, InstalledVersion, AppUpdateUrl);

            try
            {
                if (uf.CheckForUpdate(IsXML))
                {
                    if (MessageBox.Show("An update is available. Would you like to download it?", "New version", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                        uf.DownloadFile();
                    else
                        Environment.Exit(-1);
                }
                else
                {
                    if (!Silent)
                        MessageBox.Show("No update available");
                    Environment.Exit(-1);
                }
            }
            catch (Exception ex)
            {
                if (!Silent)
                    MessageBox.Show(ex.Message, "Error");
                Environment.Exit(-1);
            }
        }

        private void cancelDownload_Click(object sender, EventArgs e)
        {

            if (MessageBox.Show("Do you really want stop download?", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes)
            {
                uf.CancelDownload();
                this.Close();
            }
        }
    }
}
